< previous page page_357 next page >

Page 357
Objects
COM objects (which adhere to the Windows Common Object Model) are fundamental to the operation of Visual Basic and the Windows OLE subsystems. They are not used at all by the core Win32 API functions; however, there may be cases where you will need to pass objects or object pointers to the OLE API functions.
An object is always referenced by an interface. Logically, an interface is a group of functions that are related to each other and can be used to perform operations on the object. An object can expose many interfaces, and each interface has a function, QueryInterface, that can be used to request a different interface to the object.
When you look at the OLE documentation, you'll see that interface names always begin with the letter I. The two most important interfaces you need to know about are IUnknown and IDispatch.
IUnknown is actually a part of every interface. It controls reference counting so objects can track when they are free to delete themselves. It also includes the QueryInterface function that allows programmers to navigate between interfaces. The IUnknown variable type is supported by Visual Basic, though when you set an object into an IUnknown variable, you still cannot access the methods directly from Visual Basic:
Dim myObject As IUnknown
Set myObject = any object
You'll use the IUnknown type with some OLE API calls in cases where the function retrieves an interface pointer of unknown type.
IDispatch is the interface that supports a technology called Automation (sometimes referred to as OLE Automation or ActiveX automation). When you assign an object into a Visual Basic variable with the type Object, it contains a pointer to the IDispatch interface for the object.
Dim myObject As Object
Set myObject = an object that supports the IDispatch interface
Internally, an interface is a table of pointers to functions. When an object is passed as a parameter, the actual data passed is a pointer to this table. Both the IUnknown and IDispatch variable types actually store a pointer to an interface, thus they are both 32-bit values. You can use the Visual Basic ObjPtr operator to obtain the value of this pointer, though in fact you will rarely need to do so.
In the C/C++ documentation, you will generally see two types of object parameters:

 
< previous page page_357 next page >